package com.example.interceptmybatis.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.example.interceptmybatis.handler.InjectHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBaitsConfig {
    @Bean
    public MybatisPlusInterceptor mybaitsPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 添加分页插件
        interceptor.addInnerInterceptor(paginationInnerInterceptor());

        return interceptor;
    }

    public PaginationInnerInterceptor paginationInnerInterceptor(){
        PaginationInnerInterceptor interceptor = new PaginationInnerInterceptor();
        // 开启合理分页
        interceptor.setOverflow(true);

        return interceptor;
    }

    @Bean
    public MetaObjectHandler injectHandler(){
        return new InjectHandler();
    }
}
